package com.ln.lnzw.activity;

import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.ln.lnzw.R;
import com.ln.lnzw.base.BaseActivity;
import com.ln.lnzw.bean.ConsultationCeplydetailBean;
import com.ln.lnzw.bean.ConsultationReplyBean;
import com.ln.lnzw.net.HttpMethods;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by wuwei on 2018/6/12.
 * 咨询回复详情页
 */

public class ConsultationReplyDetailsActivity extends BaseActivity {


    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_bianhao)
    TextView tvBianhao;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_bumen)
    TextView tvBumen;
    @BindView(R.id.tv_zhuti)
    TextView tvZhuti;
    @BindView(R.id.tv_shixiang)
    TextView tvShixiang;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.tv_huifuname)
    TextView tvHuifuname;
    @BindView(R.id.tv_huifutime)
    TextView tvHuifutime;
    @BindView(R.id.tv_huifucontent)
    TextView tvHuifucontent;
    private String id;
    private ConsultationCeplydetailBean consultationBean;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_consultation_reply_details);
        ButterKnife.bind(this);
        id=getIntent().getStringExtra("id");
        initData();
//        setView();
    }

    private void initData() {
        HttpMethods.getInstanceCenter().getInstanceCenter().info.getConsultationCeplydetail(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ConsultationCeplydetailBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {


                    }

                    @Override
                    public void onNext(ConsultationCeplydetailBean consultationCeplydetailBean) {
                        if ("200".equals(consultationCeplydetailBean.getCode())){
                            consultationBean=consultationCeplydetailBean;
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {
                        getData(consultationBean);
                    }
                });

    }

    private void getData(ConsultationCeplydetailBean consultationBean) {
        tvBianhao.setText(consultationBean.getResult().getApplySearchNumber());
        tvTime.setText(consultationBean.getResult().getApplyCreateTime());
        tvName.setText(consultationBean.getResult().getApplyUsername());
        tvBumen.setText(consultationBean.getResult().getApplyDepartmentName());
        tvZhuti.setText(consultationBean.getResult().getApplyTitle());
        tvShixiang.setText(consultationBean.getResult().getApplyProcessName());
        tvContent.setText(consultationBean.getResult().getApplyContent());
        Log.i("478", "getData: "+consultationBean.getResult().getReplys().toString());
       if (consultationBean.getResult().getReplys().isEmpty()){
           tvHuifuname.setText("暂无");
           tvHuifutime.setText("暂无");
           tvHuifucontent.setText("暂无");
       }else{
           tvHuifuname.setText(consultationBean.getResult().getReplys().get(0).getApprovePerson());
           tvHuifutime.setText(consultationBean.getResult().getReplys().get(0).getApproveTime());
           tvHuifucontent.setText(consultationBean.getResult().getReplys().get(0).getApproveContent());
       }


    }
    @OnClick(R.id.iv_back)
    public void onViewClicked() {
       finish();
    }
}
